package cn.hzsckj.functional.selenium;

import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.rules.TestRule;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import cn.hzsckj.functional.selenium.Selenium2;
import cn.hzsckj.functional.selenium.SeleniumSnapshotRule;
import cn.hzsckj.functional.selenium.WebDriverFactory;

/**
 * 使用Selenium的功能测试基类.
 * 
 * 在BaseFunctionalTestCase的基础上，在整个测试期间仅启动一次Selenium.
 * 
 * @author jackChen
 */
public class BaseSeleniumTestCase{

	protected static Selenium2 s;
	
	public StringBuffer verificationErrors = new StringBuffer();

	// 出错时截屏的规则
	@Rule
	public TestRule snapshotRule = new SeleniumSnapshotRule(s);
	
	protected static String baseUrl;

	@BeforeClass
	public static void initSelenium() throws Exception {
		createSeleniumOnce();
	}

	/**
	 * 创建Selenium，仅创建一次.
	 */
	protected static void createSeleniumOnce() throws Exception {
		if (s == null) {
			// 根据配置创建Selenium driver.
			String driverName = "firefox";
			baseUrl = "http://www.taobao.com";
			WebDriver driver = WebDriverFactory.createDriver(driverName);
			s = new Selenium2(driver, baseUrl);
			s.setStopAtShutdown();
		}
	}
}
